<template>
  <div class="gallery">
    <div class="wrapper">
      <swiper :options="swiperOption" v-if="showSwiper" ref="mySwiper">
        <swiper-slide
          v-for="item of imgList"
          :key="item.id"
        ><img class="swiper-img" :src="item.imgUrl" alt="">
        </swiper-slide>
        <div class="swiper-pagination" slot="pagination"></div>
      </swiper>
    </div>
  </div>
</template>

<script>
export default {
  name: 'CommonGallery',
  props: {
    imgList: Array
  },
  data () {
    return {
      timer: null,
      swiperOption: {
        autoplay: false,
        loop: false,
        width: innerWidth,
        direction: 'horizontal',
        setWrapperSize: true,
        autoHeight: true,
        pagination: '.swiper-pagination',
        paginationType: 'fraction',
        observeParents: true,
        observer: true // 1.监听DOM对象如果发生变化,就会自动刷新refresh
      }
    }
  },
  // 1.非响应式属性(没有getter 和setter), 不会导致计算属性更新, 没有updated?
  computed: {
    showSwiper () {
      return this.imgList.length
    }
  }
}
</script>

<style lang="stylus" scoped>
  .gallery
    display flex
    flex-flow column nowrap
    justify-content center
    overflow hidden
    position fixed
    top 0
    left 0
    right 0
    bottom 0
    z-index 99
    height 100%
    background #111
    color #fff
    .wrapper
      flex none
      width 100%
      height 0
      padding-bottom 67%
      color #fff
      .swiper-img
        width 100%
      .swiper-pagination
        position fixed
        left 0
        right 0
        bottom .5rem
</style>
